// run: $exec < input
#include <iostream>
#include <algorithm>
#include <vector>

struct data { int v; int p; };
bool operator<(data const & a, data const & b)
{
	return a.v < b.v;
}

int const maxn = 1000007;
int head[maxn], end_point[2 * maxn], next[2 * maxn];
int f[maxn];
bool vis[maxn];
int father[maxn];
int alloc = 2;
std::vector<std::vector<data>> da;
int n, m;

void add_edge(int u, int v)
{
	end_point[alloc] = v; next[alloc] = head[u]; head[u] = alloc++;
}

int dfs(int x)
{
	if (vis[x]) return f[x];
	vis[x] = true;
	int ret = 1;
	for (int p = head[x]; p; p = next[p]) {
		int v = end_point[p];
		ret = std::max(ret, dfs(v) + 1);
	}
	return f[x] = ret;
}

int get_father(int u)
{
	return u == father[u] ? u : (father[u] = get_father(father[u]));
}

void set_union(int u, int v)
{
	int tu = get_father(father[u]);
	int tv = get_father(father[v]);
	if (tu != tv) father[tu] = tv;
}

int main()
{
	std::cin >> n >> m;
	da.resize(n);
	for (int i = 0; i < n; i++) {
		da[i].resize(m);
		for (int j = 0; j < m; j++) {
			std::cin >> da[i][j].v;
			da[i][j].p = i * m + j;
			father[da[i][j].p] = da[i][j].p;
		}
	}
	// merge equal
	for (int i = 0; i < n; i++) {
		auto v = da[i];
		std::sort(v.begin(), v.end());
		for (int j = 0; j < m - 1; j++)
			if (v[j].v == v[j + 1].v) set_union(v[j].p, v[j + 1].p);
	}
	for (int j = 0; j < m; j++) {
		std::vector<data> v;
		for (int i = 0; i < n; i++) v.push_back(da[i][j]);
		std::sort(v.begin(), v.end());
		for (int i = 0; i < n - 1; i++)
			if (v[i].v == v[i + 1].v) set_union(v[i].p, v[i + 1].p);
	}

	// add_edge
	for (int i = 0; i < n; i++) {
		auto v = da[i];
		std::sort(v.begin(), v.end());
		for (int j = 0; j < m - 1; j++) {
			if (v[j].v == v[j + 1].v) continue;
			add_edge(get_father(v[j + 1].p), get_father(v[j].p));
		}
	}

	for (int j = 0; j < m; j++) {
		std::vector<data> v;
		for (int i = 0; i < n; i++) v.push_back(da[i][j]);
		std::sort(v.begin(), v.end());
		for (int i = 0; i < n - 1; i++) {
			if (v[i].v == v[i + 1].v) continue;
			add_edge(get_father(v[i + 1].p), get_father(v[i].p));
		}
	}

	for (int i = 0; i < n * m; i++)
		if (!vis[get_father(i)]) dfs(get_father(i));
	int t = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) std::cout << f[get_father(t++)] << ' ';
		std::cout << '\n';
	}
}

